package com.hzhh123.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * hzhh123
 * 2019/4/2 9:51
 * mybatis-plus 设置自动填充全局bean属性
 */
@Slf4j
@Component
public class MyBatisMetaObjectHandler implements MetaObjectHandler {
    /**
     * 新增时自动填充
     *
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("[mybatis-plus新增时自动填充]");
        this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
    }

    /**
     * 更新时自动填充
     *
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("[mybatis-plus更新时自动填充]");
        this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
    }
}
